import os

from flask import Flask
from flask_cors import CORS

from config import BaseConfig
from extensions import init_plugs
from view import init_bps


def create_app():
    app = Flask(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

    # 启用CORS，允许所有源访问
    CORS(app)

    # 引入配置
    app.config.from_object(BaseConfig)

    # 注册flask组件
    init_plugs(app)

    # 注册蓝图
    init_bps(app)

    return app


app = create_app()

if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0', port=9778)
